/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yy.bugzillahelp.ui.list;

import com.yy.bugzillahelp.MainFrame;
import com.yy.bugzillahelp.action.BugAction;
import com.yy.bugzillahelp.data.BugDetailData;
import com.yy.bugzillahelp.data.server.ServerData;
import com.yy.bugzillahelp.db.BugzillaHelpDB;
import com.yy.bugzillahelp.tool.SQLTool;
import java.awt.BorderLayout;
import java.sql.Connection;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 *
 * @author Alan
 */
public class BugListPanel extends JPanel {

    private ServerData connectData;
    private BugListTable table;

    public BugListPanel(ServerData connectData) {
        this.connectData = connectData;
        initComponents();
        setDatas();
    }

    public static void main(String[] args) {
        JFrame jFrame = new JFrame("Bug List Panel");
        jFrame.getContentPane().add(new BugListPanel(MainFrame.CONNECT_DATA));
        jFrame.setSize(800, 600);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setLocationRelativeTo(null);
        jFrame.setVisible(true);
    }

    private void initComponents() {
        this.setLayout(new BorderLayout());
        table = new BugListTable(connectData);
        this.add(new JScrollPane(table));
    }

    private void setDatas() {
        Connection con = BugzillaHelpDB.getConnection();
        ArrayList<BugDetailData> datas = BugAction.searchAll(con, connectData.getId());
        SQLTool.closeConnection(con);

        table.setDatas(datas);
    }
}
